package org.cerberus.platform.share;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

import org.cerberus.platform.internal.domain.IComponentClass;

public class BinaryPlatformInputStream implements IPlatformInputStream {

	private InputStream stream;
	private ObjectInputStream ostream;
	
	public BinaryPlatformInputStream(InputStream stream) throws IOException {
		this.stream = stream;
		this.ostream = new ObjectInputStream(stream);
	}
	
	@Override
	public Object[] readChange() throws IOException {
		Object[] o = new Object[3];
		o[0] = Integer.valueOf(ostream.readInt());
		o[1] = Integer.valueOf(ostream.readInt());
		o[2] = Integer.valueOf(ostream.readInt());;
//		try {
//			o[2] = ostream.readObject();
//		} catch (ClassNotFoundException e) {
//		};
		return o;
	}

	@Override
	public IComponentClass readNewClass() throws IOException {
		return null;
	}

	@Override
	public Object[] readNewObject() throws IOException {
		return null;
	}

	@Override
	public String readRemoveClass() throws IOException {
		return null;
	}

	@Override
	public Integer readRemoveObject() throws IOException {
		return null;
	}

	@Override
	public CommuncationType readType() throws IOException {
		short s = ostream.readShort();
		if (s == CommuncationType.CHANGE.ordinal()) {
			return CommuncationType.CHANGE;
		} else if (s == CommuncationType.EOF.ordinal()) {
			return CommuncationType.EOF;
		}
		
		return null;
	}

	@Override
	public Integer readPlatformID() {
		return null;
	}

}
